/*
 * Copyright (c) 2022，公司名称
 * All rights reserved.
 * 文件名称：low_uart.h
 * 摘要：高边串口
 * 当前版本：V1.0.0,WCD,2023/1/10,初版
 * 历史版本：Vx.x.x，编写者/修改者，修改时间，修改内容（重大发布时，总结重点变更内容）
 */

#ifndef LOW_UART_H
#define LOW_UART_H
#include <stdint.h>
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓应用层数据定义开始↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
#if 1
#include "lin_msg.h"

#define LOW_UART30_TX_TIME (10u)
#define LOW_UART30_RX_TIME (1u)

#define LOW_UART_BAUD (115200u)
#define UART_LEN (8u)


/* Response Field Length Select */
typedef enum
{
    RFDL_0_byte_and_checksum,
    RFDL_1_byte_and_checksum,
    RFDL_2_byte_and_checksum,
    RFDL_3_byte_and_checksum,
    RFDL_4_byte_and_checksum,
    RFDL_5_byte_and_checksum,
    RFDL_6_byte_and_checksum,
    RFDL_7_byte_and_checksum,
    RFDL_8_byte_and_checksum
} RFDL_Type;

typedef enum Voltage_Type
{
    VOLTAGE_INVALID,
    VOLTAGE_VALID,
    VOLTAGE_INLAY,
    VOLTAGE_OVER
} Voltage_Typedef;

typedef enum
{
    MDL_9_data,
    MDL_1_data,
    MDL_2_data,
    MDL_3_data,
    MDL_4_data,
    MDL_5_data,
    MDL_6_data,
    MDL_7_data,
    MDL_8_data,
    MDL_9_data0
} MDL_Type;

typedef enum
{
    ADC_VALUE_VALID = 0,
    ADC_VALUE_OPEN,
    ADC_VALUE_SHORT
} ADC_VALUE_EM;
typedef enum
{
    PTC_MODE_INVALID = 0u,
    PTC_MODE_TEMP,
    PTC_MODE_POWER
} PTC_MODE_Type;
typedef enum
{
    IGBT_ST_VALID = 0,
    IGBT_ST_OPEN,
    IGBT_ST_SHORT
}IGBT_ST_type;
typedef enum
{
    /*low*/
    PTC_ERROR_NONE = 0,
    PTC_ERROR_LOCK,
    PTC_ERROR_OVER_TEMP,
    PTC_ERROR_HOT_TEMP,
    PTC_ERROR_PCB_OVER_125,
    PTC_ERROR_12V_HIGH,
    PTC_ERROR_12V_LOW,
    PTC_ERROR_NTC_OPEN,
    PTC_ERROR_NTC_SHORT,
    PTC_ERROR_LIN_MODE_INVALID,
    /*high*/
   PTC_HIGH_CUR60A,
    PTC_HIGH_HV_OVER,
    PTC_HIGH_HV_INLAY,
    PTC_HIGH_CUR30A,
    PTC_HIGH_V15_LOW,
    PTC_HIGH_IGBT_SHORT,
    PTC_HIGH_IGBT_OPEN,
    PTC_HIGH_WATER_NTC_OPEN,
    PTC_HIGH_WATER_NTC_SHORT,
    PTC_PTC_MODE_INVALID,
    PTC_HVH_OFF,
    PTC_ERROR_PCB_OVER_120
}ptc_error_en;
typedef union
{
    uint8_t data[UART_LEN];
    struct
    {
        /*1*/
        PTC_MODE_Type mode: 2;
        HVH_ON_OFF_e ptc_off_on: 2;
        uint8_t reserved5: 4;
        /*2*/
        uint8_t pwm_percent: 8;
        /*3*/
        uint8_t set_temp: 8;
        /*4*/
        uint8_t act_temp: 8;
        /*5*/
        uint8_t in_temp: 8;
        /*6*/
        uint8_t act_temp_deci: 8;
        /*7*/
        ptc_error_en ptc_error_status: 5;
        uint8_t reserved3: 3;
        /*8*/
        uint8_t checksum: 8;
    } sig;
} low_uart_tx_struct;

typedef union
{
    uint8_t data[UART_LEN];
    struct
    {
        /*1*/
        uint8_t dc_curr: 8;
        /*2*/
        uint8_t hv_voltage: 8;
        /*3*/
        uint8_t ptc_status: 8;
        /*4*/
        uint8_t pcb_temp: 8;
        /*5*/
        uint8_t IGBT_error_num:2;
        ADC_VALUE_EM ntc_status:2;
        HVH_HV_Voltage_Valid_e HV_voltage_st:2;
        HVH_Off_ShrtCurr_e cur_short:1;
        EM_TRUE_FALSE v15_inlay: 1;
        /*6*/
        IGBT_ST_type IGBT_status: 2;
        EM_TRUE_FALSE cur_over30:1;
        ptc_error_en ptc_all_error_status: 5;
        /*7*/
        uint8_t power: 8;
        /*8*/
        uint8_t checksum: 8;

    } sig;
} low_uart_rx_struct;
extern low_uart_rx_struct low_uart_rx_st ;
extern low_uart_tx_struct low_uart_tx_st ;
#endif
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑应用层数据定义结束↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/

void uart_send(uint8_t const *logBuf, uint32_t logLen);
/*
 * 函数介绍: 串口时钟初始化
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void low_uart_clock_init(void);
/*
 * 函数介绍: 串口初始化
 * 参数:
 * 返回值: {*}
 * 备注:
 */
void low_uart_init(void);

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓应用层函数定义开始↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
#if 1
void low_uart30_rx_tx_handle(void);
#endif
/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑应用层函数定义结束↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
#endif
